#!/bin/bash
echo "Building Debian Package"
mkdir -p pkg/nostril/usr/share/nostril/ui/
mkdir -p pkg/nostril/usr/bin/
mkdir -p pkg/nostril/usr/share/man/man1/
mkdir -p pkg/nostril/usr/share/doc/nostril/
mkdir -p pkg/nostril/usr/share/applications/
mkdir -p pkg/nostril/DEBIAN

strip -o pkg/nostril/usr/bin/nostril nostril
cp -r data/ui pkg/nostril/usr/share/nostril/
cp -r data/icons pkg/nostril/usr/share/
cp resources/xdesktop/nostril.desktop pkg/nostril/usr/share/applications/
cp pkg/debian/copyright pkg/nostril/usr/share/doc/nostril/
cp pkg/debian/changelog pkg/nostril/usr/share/doc/nostril/
gzip -9 pkg/nostril/usr/share/doc/nostril/changelog
cp resources/manpage/nostril.1 pkg/nostril/usr/share/man/man1/
gzip -9 pkg/nostril/usr/share/man/man1/nostril.1

SIZE=`du -c -s pkg/nostril/usr | tail -n1 |  cut -f1`
sed s/___SIZE/$SIZE/g pkg/debian/control > pkg/nostril/DEBIAN/control

chown -R root:root pkg/nostril/usr

dpkg-deb -z6 -Zgzip --build pkg/nostril

sudo rm -rf pkg/nostril

echo "Finished Building Debian Package"